//
//  LXAlbumCell.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/26.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXAlbumCell.h"

@implementation LXAlbumCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews{
    self.userImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.userImage];
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(10);
        make.width.height.mas_equalTo(80);
    }];
    
    self.myLitleLabel = [[UILabel alloc]init];
    self.myLitleLabel.font  =[UIFont systemFontOfSize:17];
    [self.contentView addSubview:self.myLitleLabel];
    [self.myLitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userImage.mas_top);
        make.left.equalTo(self.userImage.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(30);
    }];

    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.font = [UIFont systemFontOfSize:15];
    self.timeLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.myLitleLabel.mas_bottom).offset(5);
        make.left.equalTo(self.myLitleLabel);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(20);
    }];

    UIImageView *playImage = [[UIImageView alloc]init];
    playImage.image = [UIImage imageNamed:@"find_albumcell_play@2x.png"];
    [self.contentView addSubview:playImage];
    [playImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(9);
        make.left.equalTo(self.timeLabel);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(12);
    }];
    
    self.playLabel = [[UILabel alloc]init];
    self.playLabel.font = [UIFont systemFontOfSize:15];
    self.playLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.playLabel];
    [self.playLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).offset(5);
        make.left.equalTo(playImage.mas_right).offset(5);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(60);
    }];
    
    UIImageView *countImage = [[UIImageView alloc]init];
    countImage.image = [UIImage imageNamed:@"album_tracks@2x.png"];
    [self.contentView addSubview:countImage];
    [countImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.playLabel);
        make.left.equalTo(self.playLabel.mas_right).offset(10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(20);
    }];
    
    self.countLabel = [[UILabel alloc]init];
    self.countLabel.font = [UIFont systemFontOfSize:15];
    self.countLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.countLabel];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(countImage.mas_top);
        make.left.equalTo(countImage.mas_right).offset(5);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(20);
    }];
}

-(void)setCellModel:(LXAlbumModel *)cellModel{
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:cellModel.coverLarge] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    self.myLitleLabel.text = cellModel.title;
    self.timeLabel.text = [NSString stringWithFormat:@"更新%@",[LXTimeTool getDateWithUpdatedAt:cellModel.updatedAt]];
    if (cellModel.playTimes >10000) {
        self.playLabel.text =[NSString stringWithFormat:@"%ld.%ld万",cellModel.playTimes/10000,cellModel.playTimes/1000%10];
    }else{
        self.playLabel.text = [NSString stringWithFormat:@"%ld",cellModel.playTimes];
    }
    self.countLabel.text = [NSString stringWithFormat:@"%ld集",cellModel.tracks];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
